package com.asu.dltalk.control;

import com.asu.dltalk.model.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.*;

public class XmppAPI implements MessageListener {
	
	XMPPConnection connection;
	PacketTypeFilter filter = new PacketTypeFilter(Message.class);
	handler mhandle;
	
	private String username = null;
	private String password = null;
	
	public XmppAPI()
	{
		mhandle = new TextHandler();
	}
	
	public void setUser(String uname)
	{
		username = uname;
	}
	
	public void setPass(String pword)
	{
		password = pword;
	}
	
	public boolean standBy(String resrc)
	{
		if(username != null && password != null)
		{
			login(username, password, resrc);
			return true;
		}
		else
		{
			return false;
		}
	}

	@Override
	public void processMessage(Chat arg0, Message arg1) {
		// TODO Auto-generated method stub
		
	}
	
	private void login(String uname, String pword, String resrc)
	{
		ConnectionConfiguration config = null;
		try
		{
			connection = new XMPPConnection(config);
			connection.connect();
			connection.login(uname, pword);
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}

}
